<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
	<title>积分翻倍</title>
	<meta name="renderer" content="webkit|ie-comp|ie-stand">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8" />
	<meta http-equiv="Cache-Control" content="no-siteapp" />
	<!--<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />-->
	<script src="__JS__/phone.js" type="text/javascript" charset="utf-8"></script>
	<script src="__JS__/jquery-2.1.0.js" type="text/javascript" charset="utf-8"></script>
	<script src="__JS__/vue/npmvue.js" type="text/javascript" charset="utf-8"></script>
	<!--  	<script src="https://cdn.jsdelivr.net/npm/vue"></script>-->
	<link rel="stylesheet" type="text/css" href="__CSS__/common/common.css" />
	<link rel="stylesheet" type="text/css" href="__CSS__/index/index.css" />
</head>

<body>
	<div id="app">
		<div class="backImage">
			<img src="__STATIC__/images/backImg.png" />
		</div>
		<!--<div class="header">
			</div>-->
		<ul class="actionLists">
			<li v-for="(item,index) in actionList" @click="enterCoupon(item)">
				<div class="actionImg">
					<img :src="item.action_img" />
				</div>
				<div class="actionStatus">
					<div class="actionName">
						<img src="__STATIC__/images/contentIcon.png" />
						{{item.title}}
					</div>
					<div class="actionTime">
						<img src="__STATIC__/images/timeIcon.png" />
						活动时间：{{item.starttime}} ~ {{item.endtime}}
					</div>
					<div class="rightImg">
						<p v-if='datetime >= item.starttime && datetime <= item.endtime'>进行中</p>
						<p v-if='datetime < item.starttime'>未开始</p>
						<p v-if='datetime > item.endtime'>已结束</p>
						<img class="img" src="__STATIC__/images/timeDiv.png" />
					</div>
				</div>
			</li>
		</ul>
		<div class="loadingDiv" v-show="isLoading">
			<div class="loadingImg">
				<img src="__STATIC__/images/loading.gif" />
				<p>加载中，请稍后...</p>
			</div>
		</div>
	</div>
</body>
<script>
	var vm = new Vue({
		el: "#app",
		data() {
			return {
				actionList: [],
				mobile: '{$mobile}',
				cardNo: '',
				score: '',
				datetime: '',
				isLoading: true
			}
		},
		created() {
			//				获取活动列表
			this.getActions();
		
			var datetime = this.getDate();
			console.log(datetime)
			this.datetime = datetime;
		},
		methods: {
			enterCoupon(value) {
				console.log(value);
				//添加点击活动记录
				this.actionHits(value.id);
				//判断当前时间是否在活动运营时间范围内
				var datetime = this.getDate();
				console.log(value.starttime)
				console.log(datetime)
				console.log(value.endtime)

				window.location.href = '/index/Index/coupons?actionid=' + value.id;

				// if (datetime >= value.starttime && datetime <= value.endtime) {
				// 	//判断该用户参与次数是否超过每人应参加该活动次数
				// 	if (value.joined_num < value.join_number) {
				// 		if (value.joined_today < value.join_eachday) {
				// 			window.location.href = '/index/Index/coupons?actionid=' + value.id;
				// 		} else {
				// 			window.alert("您已达到此活动每天的参与次数")
				// 		}
				// 	} else {
				// 		window.alert("每人限兑1次\n您已完成兑换")
				// 	}
				// } else {

				// 	if (datetime < value.starttime) {
				// 		window.alert('该活动未开始');
				// 	}

				// 	if (datetime > value.endtime) {
				// 		window.alert('该活动已结束');
				// 	}

				// }
			},
			getActions(mobile) {
				//					获取活动列表
				var that = this;
				$.ajax({
					type: "post",
					url: "/api/Getinfo/getActions",
					async: true,
					data: {
						mobile: '{$mobile}'
					},
					dataType: "json",
					success: function (res) {
						console.log(res)
						that.actionList = res.data;
						that.isLoading = false;
					}
				});
			},
			
			actionHits(actionId) {
				//添加点击活动记录
				var that = this;
				$.ajax({
					type: "post",
					url: "/api/Active/actionClick",
					async: true,
					data: {
						mobile: '{$mobile}',
						actionId: actionId,
					},
					dataType: "json",
					success: function (res) {
						console.log(res)
					}
				});
			},
			getDate() {
				var myDate = new Date();
				var year2 = myDate.getYear();        // 获取当前年份(2位)
				var year4 = myDate.getFullYear();    // 获取完整的年份(4位,1970-????)
				var month = myDate.getMonth() + 1;       // 获取当前月份(0-11,0代表1月)
				var day = myDate.getDate();        // 获取当前日(1-31)
				var week = myDate.getDay();         // 获取当前星期X(0-6,0代表星期天)
				var time = myDate.getTime();        // 获取当前时间(从1970.1.1开始的毫秒数)
				var hour = myDate.getHours();       // 获取当前小时数(0-23)
				var minute = myDate.getMinutes();     // 获取当前分钟数(0-59)
				var seconds = myDate.getSeconds();     // 获取当前秒数(0-59)
				var millisecond = myDate.getMilliseconds();    // 获取当前毫秒数(0-999)
				var dates = myDate.toLocaleDateString();     // 获取当前日期
				var mytime = myDate.toLocaleTimeString();     // 获取当前时间
				var datetime = myDate.toLocaleString();        // 获取日期与时间
				if (month < 10) {
					month = "0" + month;
				}
				if (day < 10) {
					day = "0" + day;
				}
				if (hour < 10) {
					hour = "0" + hour;
				}
				if (minute < 10) {
					minute = "0" + minute;
				}
				if (seconds < 10) {
					seconds = "0" + seconds;
				}
				var dateTime = year4 + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + seconds;
				//					console.log(dateTime);
				return dateTime;
			}
		}
	})
</script>
<script type="text/javascript">
	window.alert = function (name) {
		var iframe = document.createElement("IFRAME");
		iframe.style.display = "none";
		iframe.setAttribute("src", 'data:text/plain,');
		document.documentElement.appendChild(iframe);
		window.frames[0].window.alert(name);
		iframe.parentNode.removeChild(iframe);
	};
</script>

</html>